<template>
	<view class="content">
		<u-navbar title="我的订单" safeAreaInsetTop placeholder fixed autoBack>
			<view class="u-nav-slot" slot="right">
				<text class="color_san text_a" @click="goRefundOrder">退款</text>
			</view>
		</u-navbar>
		<u-sticky bgColor="#fff">
			<u-tabs :list="list1" lineColor="rgba(243, 39, 28, 1)" :current="currenttabtow" @click="clicktabtow"
				:activeStyle="{
		    	    color: '#000000',
		    	    fontWeight: 'bold',
		    	    transform: 'scale(1.05)'
		    	}" :inactiveStyle="{
		    	            color: 'rgba(102, 102, 102, 1)',
		    				fontWeight: 'bold',
		    	            transform: 'scale(1)'
		    	        }" itemStyle="padding-left: 15px; padding-right: 15px; height: 44px;"></u-tabs>
		</u-sticky>
		<view class="padding_lrb">
			<view class="ffffff padding border_2 margin_top" v-for="item in list.data" :key="item.id"
				@click="goOrderInfo(item.id)">
				<view class="flexbetween">
					<view class="flexleft">
						<view class="number margin_right2 yihang">订单编号：{{item.order_no}}</view>
					</view>
					<view class="hongsetext" style="color: rgba(19, 196, 99, 1);" v-show="item.state==-1">已取消</view>
					<view class="hongsetext" style="color: rgba(255, 168, 0, 1);" v-show="item.state==1">待付款</view>
					<view class="hongsetext" style="color: rgba(255, 0, 0, 1);" v-show="item.state==3">待服务</view>
					<view class="hongsetext" style="color: rgba(243, 39, 28, 1);" v-show="item.state==4">服务中</view>
					<view class="hongsetext" style="color: rgba(19, 196, 99, 1);" v-show="item.state==5">待评价</view>
					<view class="hongsetext" style="color: rgba(19, 196, 99, 1);" v-show="item.state==6">已完成</view>
					<view class="hongsetext" style="color: rgba(19, 196, 99, 1);" v-show="item.state==8">已退款</view>
				</view>
				<view class="flexbetween xiahuax margin_top">
					<view class="shilitu">
						<image :src="item.service_image_text" mode="widthFix"></image>
					</view>
					<view class="" style="width: 74%;">
						<view class="yihang text_a color_san">{{item.service_name}}</view>
						<view class="flexbetween margin_top5">
							<view class="qianshu">¥{{item.total_price}}</view>
							<view class="shuliang">X1</view>
						</view>
					</view>
				</view>
				<!-- 所有按钮 -->
				<view class="flexright margin_top">
					<view class="huisebtn" v-show="item.can_cancel" @click.stop="cancelOrder(item.id)">取消订单</view>
					<view class="huangsebtn margin_left3" v-show="item.can_pay" @click.stop="atoncePay(item)">立即付款
					</view>
					<view class="huisebtn" v-show="item.can_refund" @click.stop="goApplyRefund(item.id)">申请退款</view>
					<view class="huangsebtn margin_left3" v-show="item.can_receipt" @click.stop="sureOrder(item.id)">
						确认已服务</view>
					<view class="huangsebtn margin_left3" v-show="item.can_comment" @click.stop="estimate(item.id)">立即评价
					</view>
					<view class="huisebtn" v-show="item.can_del" @click.stop="deletorder(item.id)">删除订单</view>
				</view>
			</view>
			<view class="flexcenter placeholderBoxTop" v-if="!list.data.length">
				<image class="placeholderBox" src="/static/placeholderimg.png" mode="widthFix"></image>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				currenttabtow: 0, //0=全部,1=待付款,3=待服务,4=服务中,5=待评价,6=已完成
				list1: [{
					name: '全部',
				}, {
					name: '待付款',
				}, {
					name: '待服务',
				}, {
					name: '服务中',
				}, {
					name: '待评价',
				}, {
					name: '已完成',
				}],
				page: 1,
				limit: 12,
				list: {
					data: []
				},
			}
		},
		onShow() {
			this.init()
		},
		methods: {
			init(isPage, page) {
				let _this = this;
				let obj = {
					"0": 0,
					"1": 1,
					"2": 3,
					"3": 4,
					"4": 5,
					"5": 6
				}
				httpRequest.request("/api/service_order/orderlist", 'GET', {
					page: page || 1,
					state: obj[this.currenttabtow],
				}, false, false, true).then(res => { //我的订单接口
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							_this.list = res.data
							_this.list.data = resList.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},

			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page)
			},
			cancelOrder(id) {
				httpRequest.modal('提示', '确定取消当前订单吗？', true, (res) => {
					if (res) {
						httpRequest.request('/api/service_order/cancel', 'POST', {
							order_id: id,
						}, false, false, true).then(res => {
							httpRequest.toast(res.msg);
							if (res.code == 1) {
								this.init()
							}
						}).catch(err => {
							httpRequest.toast(err.msg);
						})
					}
				})
			},
			goApplyRefund(id) { //申请退款
				uni.navigateTo({
					url: "/pages_mine/serviceApplyRefund?id=" + id
				})
			},
			sureOrder(id) {
				httpRequest.modal('提示', '确定当前服务已完成？', true, (res) => {
					if (res) {
						httpRequest.request('/api/service_order/receipt', 'POST', {
							order_id: id,
						}, false, false, true).then(res => {
							httpRequest.toast(res.msg);
							if (res.code == 1) {
								this.init()
							}
						}).catch(err => {
							httpRequest.toast(err.msg);
						})
					}
				})
			},
			goOrderInfo(id) { //订单详情
				uni.navigateTo({
					url: "/pages_mine/serviceOrderInfo?id=" + id
				})
			},
			clicktabtow(e) {
				this.currenttabtow = e.index;
				this.init()
			},
			atoncePay(item) {
				let data = {
					order_id: item.id,
					total_price: item.total_price
				}
				uni.redirectTo({
					url: "/pages_index/payment?msg4=" + encodeURIComponent(JSON.stringify(data))
				})
			},
			estimate(id) {
				uni.navigateTo({
					url: "/pages_mine/reportEvaluate?type=2&id=" + id
				})
			},
			deletorder(id) { //删除订单
				httpRequest.modal('提示', '确定删除当前订单吗？', true, (res) => {
					if (res) {
						httpRequest.request('/api/service_order/del', 'POST', {
							order_id: id,
						}, false, false, true).then(res => {
							httpRequest.toast(res.msg);
							if (res.code == 1) {
								this.init()
							}
						}).catch(err => {
							httpRequest.toast(err.msg);
						})
					}
				})
			},
			goRefundOrder(){ //退款
				uni.navigateTo({
					url:"/pages_mine/serviceRefundOrder"
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	// ::v-deep.u-tabs__wrapper__nav__item {
	// 	//平均分配
	// 	flex: 1;
	// }
	::v-deep.u-navbar__content__title{
			font-weight: 800;
		}
	.number {
		width: calc(100vw - 72rpx - 140rpx);
		font-size: 28rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #000000;
	}

	.huangsebtn {
		border: 2rpx solid rgba(243, 39, 28, 1);
		width: 170rpx;
		height: 67rpx;
		display: flex;
		border-radius: 120rpx;
		align-items: center;
		justify-content: center;
		font-size: 26rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: rgba(243, 39, 28, 1);
	}

	.huisebtn {
		border: 2rpx solid #666666;
		width: 170rpx;
		height: 67rpx;
		display: flex;
		border-radius: 120rpx;
		align-items: center;
		justify-content: center;
		font-size: 26rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #666666;
	}

	.xiahuax {
		padding-bottom: 30rpx;
		border-bottom: 1rpx solid rgba(153, 153, 153, .1);
	}

	.shuliang {
		font-size: 26rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: rgba(243, 39, 28, 1);
	}

	.qianshu {
		font-size: 30rpx;
		font-family: DIN Next LT Pro-Bold, DIN Next LT Pro;
		font-weight: bold;
		color: rgba(243, 39, 28, 1);
	}

	.shilitu {
		width: 134rpx;
		height: 128rpx;
		border-radius: 14rpx;
		overflow: hidden;
		image {
			width: 100%;
			height: 100%;
			border-radius: 14rpx;
		}
	}

	.hongsetext {
		width: 72rpx;
		min-width: 72rpx;
		font-size: 24rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: RGBA(255, 117, 16, 1);
	}
</style>